package src.leetcode.dp.medium_0322;

import java.util.Arrays;

public class coinChange {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.coinChange(new int[]{1, 2, 5}, 11));
    }
}


class Solution {
    public int coinChange(int[] coins, int amount) {
        int []dp = new int[amount + 1];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        for (int coin : coins) {
            for(int i = coin; i < dp.length; i++){
                if(dp[i - coin] == -1) continue;
                if(dp[i] == -1) dp[i] = dp[i - coin] + 1;
                else dp[i] = Math.min(dp[i], dp[i - coin] + 1);
            }
        }

        return dp[amount];
    }
}
